import java.util.Random;
import java.util.Scanner;
//给定一个数，求其每一位相加之和
    public class test {
        public static void max(int a,int b){
            if (a > b){
                System.out.println(a);
            }else{
                System.out.println(b);
            }
        }
        public static void max(int c,int d,int e){
            if(c > d){
                if(c > e){
                    System.out.println(c);
                }else{
                    System.out.println(e);
                }
            }else{
                if(d > e){
                    System.out.println(d);
                }else{
                    System.out.println(e);
                }
            }
        }
    public static void main(String[] args) {
            max(6,8);
            max(6,8,9);
    }
        //求斐波那契数列的第N项（迭代/循环）
    public static int fib2(int n){
        if (n == 1||n == 2){
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = -1;
        for(int i = 3;i <= n; i++){
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main11(String[] args) {
        System.out.println(fib2(1));
        System.out.println(fib2(20));
    }
        //求斐波那契数列的第N项(递归法)
    public static int fib(int n){
        if(n == 1||n == 2){
            return 1;
        }else{
            return fib(n - 1) + fib(n - 2);
        }
    }
        public static void main10(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.print("请问你要求第几项：");
            int i = sc.nextInt();
            System.out.println(fib(i));
        }
        public  static int add(int n){
            if(n < 10){
                return n;
            }
            else{
                return n % 10 + add(n / 10);
            }
        }
        public static void main9(String[] args) {
            System.out.println(add(123));
        }
        public static int sum(int n){
            if(n == 1){
                return 1;
            }
            else{
                return n + sum(n - 1);
            }
        }
        public static void main8(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入一个数:");
            int i = sc.nextInt();
            System.out.println(sum(i));
        }
        //题目：给定一个数，分别打印出其每一位
        public static void print(int n){
            if(n < 10){
                System.out.println(n);
            }
            print(n/10);
            System.out.println(n % 10);
        }
        public static void main7(String[] args) {
          print(123);
        }
        //递归求n的阶乘
        public static int fac(int n){
            if(n == 1){
                return 1;
            }
            return n * fac(n-1);
        }
        public static void main6(String[] args) {
            System.out.println("请输入一个数字：");
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int ret = fac(n);
            System.out.println(n+"的阶乘为："+ret);
        }
        //输出一个X图形
        public static void main5(String[] args) {
            Scanner sc = new Scanner(System.in);
            while (sc.hasNextInt()) {
                int n = sc.nextInt();
                for (int i = 0; i <= n; i++) {
                    for (int j = 0; j <= n; j++) {
                        if (i == j || i + j == n - 1) {
                            System.out.print("*");//不能换行
                        } else {
                            System.out.print(" ");//不能换行
                        }
                    }
                    System.out.println();
                }
            }
        }
        //如何处理多组输入，使用scann读取多组数字，并求其平均值
        public static void main4(String[] args) {
            Scanner sc = new Scanner(System.in);//可输入的前提
            int num = 0;
            int sum = 0;
            while (sc.hasNextInt()) {//IDEA控制台使用ctrl+d结束循环输入
                //括号中是为了检测是否还有下一个整形的数据，有则执行true，没有则返回false，循环结束
                int tmp = sc.nextInt();
                sum += tmp;
                num++;
            }
            System.out.println("sum=" + sum);
            System.out.println("avg=" + sum / num);
            sc.close();
        }
    public static void main3(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入你的姓名");
        String name = scan.nextLine();
        System.out.println("请输入你的年龄");
        int age = scan.nextInt();
        System.out.println("请输入你的工资");
        double salary = scan.nextDouble();
        System.out.println("你的信息如下");
        System.out.println("姓名:"+name+"\n"+"年龄:"+age+"\n"+"薪水："+salary);
        scan.close();//可有可无
    }
    public static void main2(String[] args) {
        Random random = new Random();//生成随机数前提条件，必须写
                int num = random.nextInt(100);
        Scanner scan = new Scanner(System.in);//输入前提条件，必须写
        while(true){
            System.out.println("请输入你要猜的数字");
            int i = scan.nextInt();
            if(i > num){
                System.out.println("猜大了");
            }
            else if(i == num){
                System.out.println("猜对了");
            }
            else{
                System.out.println("猜小了");
            }
        }
    }
    public static void main1(String[] args) {
        Random random = new Random();//生成随机数的前提
        int num = random.nextInt(100);//接收生成的随机数，范围是【0,100）
        Scanner scan = new Scanner(System.in);//输入前提
        while(true){
            System.out.println("请输入你要猜的数字");
            int i = scan.nextInt();
            if(i > num){
                System.out.println("猜大了");
            }
            else if(i == num){
                System.out.println("猜对了");
            }
            else{
                System.out.println("猜小了");
            }
        }
    }
}

